<template>
  <rx-dialog @handOk="handOk" @cancel="closeWindow" :oktext="i18n('withdrawList.withdrawBtn','撤回')" order="buttom" btnalign="center">
    <rx-fit>
      <div style="height:100%;width:100%;padding:20px;">
        <a-form-model :rules="rules"  :model="form"  ref="form">
          <a-form-model-item :label="i18n('withdrawList.title','标题')" :label-col="labelCol" :wrapper-col="wrapperCol">
            {{bpmInst.subject}}
          </a-form-model-item>
          <a-form-model-item :label="i18n('withdrawList.opinion','意见')" :label-col="labelCol" :wrapper-col="wrapperCol" prop="opinion">
            <a-textarea v-model="form.opinion" :placeholder="i18n('withdrawList.opinion','请填写意见','write')" ></a-textarea>
          </a-form-model-item>
        </a-form-model>
      </div>
    </rx-fit>
  </rx-dialog>
</template>
<script>
import {  RxDialog, Util, RxFit } from '@lowcode/jpaas-common-lib'
import BpmInstApi from '@/api/bpm/core/bpmInst'



export default {
  name: 'bpm-task-back',
  components: {
    RxFit,
    RxDialog,
  },
  props: {
    layerid: String,
    lydata: Object,
    destroy: Function,
    //流程实例对象
    bpmInst:{
      type: Object
    },
    //来自页面
    from: String
  },
  data() {
    return {
      labelCol: { span: 4 },
      wrapperCol: { span: 8 },
      nextJumpType:'normal',
      opinion:"",
      rules: {
        opinion: [
          { required: true, message: this.i18n('withdrawList.opRequired','意见必填'), trigger: 'blur' },
          { type:"string", max: 300, message: this.i18n('withdrawList.opLength','长度不能大于300字符'), trigger: 'blur' },
        ]
      },
      form:{
        opinion:""
      }
    }
  },
  created(){

  },
  methods: {
    i18n(name,text,key){
      return this.$ti18(name,text,"bpmInst",key);
    },
    handOk(vm){
      let self_=this;
      vm.loading=true;
      this.$refs.form.validate(valid => {
        if (valid) {
          BpmInstApi.revokeProcess(self_.bpmInst.instId,self_.form.opinion,this.from).then(res=>{
            vm.loading=false;
            if(res.success){
              Util.closeWindow(self_, 'ok')
            }
          });
        }
        else {
          vm.loading=false;
        }
      });
    },
    closeWindow() {
      Util.closeWindow(this, 'cancel')
    }
  }
}
</script>